package com.cp_smss.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.cp_smss.dao.BusinessDao;
import com.cp_smss.model.Page;
import com.cp_smss.model.Project;

@Repository("businessDao")
public class BusinessDaoImpl implements BusinessDao{
	
	@Autowired
	private SqlSession sqlSession;
	
	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}
	
	@Override
	public void editProject(Project project) {
		sqlSession.update("com.cp_smss.model.ProjectMapper.updateProject",project);
	}

	@Override
	public List<Project> listProjects(Page page) {
		return sqlSession.selectList("com.cp_smss.model.ProjectMapper.listProjects", page);
	}

	@Override
	public int addProject(Project project) {
		return sqlSession.insert("com.cp_smss.model.ProjectMapper.addProject",project);
	}

	@Override
	public void deleteProject(int[] pids) {
		sqlSession.update("deleteProject",pids);
	}
	
	public int validateProjectName(String name){
		return sqlSession.selectOne("com.cp_smss.model.ProjectMapper.validateProjectName", name);
	}

	@Override
	public Project getProjectByCondition(Project project) {
		return sqlSession.selectOne("com.cp_smss.model.ProjectMapper.getProjectByCondition",project);
	}

}
